﻿using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wicresoft.EKA.MVCExtensions;
using Wicresoft.EKA.ITSM.Business;

namespace Wicresoft.EKA.ITSM.Web.WebPortal.Controllers
{
    public class InspectionTicketController : BaseController
    {
        [Inject]
        public ISMGXJPlanObject SMGXJPlanObject { get; set; }

        [Inject]
        public ISMGXJPlanTicket SMGXJPlanTicket { get; set; }

        [Inject]
        public ICTMPeople CTMPeople { get; set; }

        [Inject]
        public IUser User { get; set; }

        [Inject]
        public override IUserInfo UserInfo { get; set; }  //每个Controller必须包含的。

        protected override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
        {
            ((IBase)SMGXJPlanObject).UserIdentify = UserName;
            ((IBase)CTMPeople).UserIdentify = UserName;
            ((IBase)SMGXJPlanTicket).UserIdentify = UserName;
            ((IBase)User).UserIdentify = UserName;
            base.OnActionExecuting(filterContext);
        }

        protected override void Dispose(bool disposing)
        {
            ((IDisposable)SMGXJPlanObject).Dispose();
            ((IDisposable)CTMPeople).Dispose();
            ((IDisposable)SMGXJPlanTicket).Dispose();
            ((IDisposable)User).Dispose();
            ((IDisposable)User).Dispose();
        }

        [Permission(Roles = "模板制定人")]
        public ActionResult Create()
        {
            ViewBag.TicketID = SMGXJPlanTicket.GetTicketID();
            ViewBag.fullname = CTMPeople.GetPeopleByLoginID(UserName).FullName;
            ViewBag.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            ViewBag.Groups = User.GetGroupAsso(UserName,"Yes").ToList();
            return View();
        }

        [Permission(Roles = "模板制定人")]
        public ActionResult Modify(string TicketID, string CheckPublic)
        {
            ViewBag.TicketID = TicketID;
            ViewBag.CheckPublics = CheckPublic;
            ViewBag.Groups = User.GetGroupAsso(UserName, "Yes").ToList();
            var lsit = SMGXJPlanTicket.GetbyID(TicketID);
            if (lsit.Submitter == UserName || Roles.Contains("管理人员"))
            {
                ViewBag.IsSubmitterOrManager = true;
            }
            else
                ViewBag.IsSubmitterOrManager = false;
            return View(lsit);
        }
    }
}